struct User{
    username: String,
    email: String,
    sign_in_count: u64,
    active: bool,
}


fn main() {
    let user1 = User{
        username: String::from("someusername123"),
        email: String::from("someone@example.com"),
        sign_in_count: 1,
        active: true,
    };

    // 如果需要修改结构体中的字段，可以使用 `mut` 关键字，一旦使用 `mut` 关键字，实例中所有的字段都会变为可变的。
    let mut user2 = User{
        username: String::from("someusername123"),
        email: String::from("someone@example.com"),
        sign_in_count: 1,
        active: true,
    };

    user2.email = String::from("anotheremail@example.com");

    println!("user2 email: {}", user2.email);

    let user3 = build_user(String::from("another@example.com"), String::from("anotherusername"));

    let _smp_user3 = simplify_build_user(String::from("another@example.com"), String::from("anotherusername"));

    // 通过结构体的字段来创建实例
    let _user4 = User{
        email: String::from("another@example.com"),
        username: String::from("anotherusername"),
        ..user1 // 拷贝 user1 中除了 email 和 username 的其他字段
    };


    // 元组结构体
    struct Color(i32, i32, i32);
    struct Point(i32, i32, i32);

    let black = Color(0, 1, 2);
    let origin = Point(2, 3, 4);

    println!("black: {},{},{}", black.0,black.1,black.2);
    println!("origin: {},{},{}", origin.0,origin.1,origin.2);
}
//函数化 创建实例
fn build_user(email: String, username: String) -> User {
    User {
        email: email,
        username: username,
        active: true,
        sign_in_count: 1,
    }
}
//简化，如果函数参数与结构体字段同名，可以使用简写方式
fn simplify_build_user(email: String, username: String) -> User {
    User{
        email,// 简写,不需要写 email: email
        username, // 简写
        active: true,
        sign_in_count: 1,
    }
}